<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_dynamicSegmentation"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map, options,
        baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
        serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
    var extent = [48.4, -7668.25, 8958.85, -55.58];
    var projection = new ol.proj.Projection({
        code:'',
        extent: extent,
        units: 'm'
    });
    new ol.supermap.MapService(baseUrl).getMapInfo().then(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [4503.62, -3861.91],
                zoom: 1,
                projection: projection,
                multiWorld: true
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        generateSpatialDataAnalystProcess();
    });

    function generateSpatialDataAnalystProcess() {
        //配置动态分段Parameters
        var generateSpatialDataParameters = new ol.supermap.GenerateSpatialDataParameters({
            routeTable: "RouteDT_road@Changchun",
            routeIDField: "RouteID",
            eventTable: "LinearEventTabDT@Changchun",
            eventRouteIDField: "RouteID",
            measureField: "",
            measureStartField: "LineMeasureFrom",
            measureEndField: "LineMeasureTo",
            measureOffsetField: "",
            errorInfoField: "",
            dataReturnOption: new ol.supermap.DataReturnOption({
                expectCount: 1000,
                dataset: "generateSpatialData@Changchun",
                deleteExistResultDataset: true,
                dataReturnMode: ol.supermap.DataReturnMode.DATASET_ONLY
            })
        });
        new ol.supermap.SpatialAnalystService(serviceUrl).generateSpatialData(generateSpatialDataParameters).then(function (serviceResult) {
            var a = serviceResult.result;
            //用专题图展示分析结果
            showAnalysisResult_ThemeGridUnique();
        });

        //构造专题图
        function showAnalysisResult_ThemeGridUnique() {
            //配置专题样式
            var style1, style2, style3;
            style1 = new ol.supermap.ServerStyle({
                fillForeColor: new ol.supermap.ServerColor(242, 48, 48),
                lineColor: new ol.supermap.ServerColor(242, 48, 48),
                lineWidth: 1
            });
            style2 = new ol.supermap.ServerStyle({
                fillForeColor: new ol.supermap.ServerColor(255, 159, 25),
                lineColor: new ol.supermap.ServerColor(255, 159, 25),
                lineWidth: 1
            });
            style3 = new ol.supermap.ServerStyle({
                fillForeColor: new ol.supermap.ServerColor(91, 195, 69),
                lineColor: new ol.supermap.ServerColor(91, 195, 69),
                lineWidth: 1
            });
            //配置专题项
            var themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3;
            themeUniqueIteme1 = new ol.supermap.ThemeUniqueItem({
                unique: "拥挤",
                style: style1
            });
            themeUniqueIteme2 = new ol.supermap.ThemeUniqueItem({
                unique: "缓行",
                style: style2
            });
            themeUniqueIteme3 = new ol.supermap.ThemeUniqueItem({
                unique: "畅通",
                style: style3
            });
            var themeUnique = new ol.supermap.ThemeUnique({
                uniqueExpression: "TrafficStatus",
                defaultStyle: new ol.supermap.ServerStyle({
                    fillForeColor: new ol.supermap.ServerColor(48, 89, 14),
                    lineColor: new ol.supermap.ServerColor(48, 89, 14)
                }),
                items: [themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3]
            });
            var themeParameters = new ol.supermap.ThemeParameters({
                themes: [themeUnique],
                datasetNames: ["generateSpatialData"],
                dataSourceNames: ["Changchun"]
            });
            new ol.supermap.ThemeService(baseUrl).getThemeInfo(themeParameters).then(function (serviceResult) {
                var result = serviceResult.result;
                if (result && result.newResourceID) {
                    var themeLayer = new ol.layer.Tile({
                        source: new ol.source.TileSuperMapRest({
                            url: baseUrl,
                            noWrap: true,
                            cacheEnabled: false,
                            transparent: true,
                            layersID: result.newResourceID,
                            tileGrid: new ol.tilegrid.TileGrid({
                                extent: extent,
                                resolutions: options.tileGrid.getResolutions()
                            }),
                            transparent: true
                        })
                    });
                    map.addLayer(themeLayer);
                }
            })
        }
    }
</script>
</body>
</html>